const express = require('express');
const router = express.Router();
const mysql = require('mysql')
const db = require('../../sql/db')
const $sql = require('../../sql/sqlMap')

const connection = mysql.createConnection(db.mysql)
connection.connect()
// 登录验证语句
const sql = $sql.admin.AddPartySecretary;

router.post('/', function (req, res, next) {
    let name = req.body.name;
    let mng_class = req.body.mng_class;
    let account = req.body.account;
    let info = req.body.info;
    console.log(req.body);
    connection.query(sql, [name, mng_class, account, info], (err, result) => {
        if (err) {
            console.log(err)
            return
        }
        if (result.insertId) {
            res.json({
                status: '0',
                msg: '团支书 ' + name + '\n 添加成功，默认登录密码123456',
                result: result
            });
            console.log(result);
        } else {
            res.json({
                status: '1',
                msg: '添加失败，' + '团支书 ' + name + ' 已存在',
                result: ''
            });
        }
    })
});

module.exports = router;
